home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
101-125
/
118
/
empire
/
src
/
source.zoo
/
cmd_general4.d
< prev
next >
Wrap
Text File
|
1987-12-02
|
12KB
|
436 lines
#include:util.g
#empire.g
#empfunc.g
proc cmd_price()bool:
Sector_t s;
Ship_t sh;
Offer_t offer;
uint offerNumber, shipNumber, cost, price, oldPrice;
int r, c;
ItemType_t what;
bool isShip, gotOffer;
gotOffer := false;
if reqSectorOrShip(&r, &c, &shipNumber, &isShip,
"Ship to sell or exchange to sell at? ") then
if isShip then
readShip(shipNumber, sh);
if sh.sh_owner ~= ThisCountryNumber then
err("you don't own that ship");
false
else
offerNumber := 0;
while
if offerNumber = World.w_offerNext then
false
else
readOffer(offerNumber, offer);
offer.of_state ~= of_ship or
offer.of_.of_shipNumber ~= shipNumber
fi
do
offerNumber := offerNumber + 1;
od;
if offerNumber ~= World.w_offerNext then
if offer.of_who ~= ThisCountryNumber then
sh.sh_price := 0;
fi;
gotOffer := true;
fi;
cost := World.w_shipCost[sh.sh_type];
write(Chout; getShipName(sh.sh_type), " \#", shipNumber);
if sh.sh_price = 0 then
writeln(Chout; " is currently not for sale");
else
writeln(Chout; " is currently offered at $", sh.sh_price,
" per ton (total $", sh.sh_price * cost, ')');
fi;
skipBlanks();
if reqPosRange(&price, 127, "New price per ton? ") then
if price = 0 then
if sh.sh_price ~= 0 then
writeln(Chout; "Lot \#",offerNumber, " withdrawn");
sh.sh_price := 0;
writeShip(shipNumber, sh);
offer.of_state := of_none;
writeOffer(offerNumber, offer);
else
writeln(Chout; "OK, ship not offered for sale");
fi;
else
writeln(Chout; "Total value is $", price * cost);
sh.sh_price := price;
writeShip(shipNumber, sh);
if not gotOffer then
offerNumber := World.w_offerNext;
World.w_offerNext := World.w_offerNext + 1;
fi;
writeln(Chout; getShipName(sh.sh_type), " \#",
shipNumber, " is now lot \#", offerNumber);
offer.of_state := of_ship;
offer.of_who := ThisCountryNumber;
offer.of_.of_shipNumber := shipNumber;
writeOffer(offerNumber, offer);
fi;
fi;
true
fi
elif doSkipBlanks() and reqCmsgpob(&what, "Set price on what? ") then
readSector(r, c, s);
if what = it_civilians or what = it_military then
err("can't sell people");
false
elif s.s_owner ~= ThisCountryNumber then
err("you don't own that sector");
false
elif s.s_type ~= s_exchange then
err("that sector is not an exchange");
false
elif s.s_efficiency < 60 then
err("exchange not efficient enough for trading");
false
else
offerNumber := s.s_threshold[it_civilians] << 8 |
s.s_threshold[it_military];
cost := getItemCost(what);
oldPrice := s.s_threshold[what] * cost;
if offerNumber ~= 0 then
offerNumber := offerNumber - 1;
readOffer(offerNumber, offer);
if offer.of_who ~= ThisCountryNumber then
oldPrice := 0;
fi;
gotOffer := true;
fi;
write(Chout; getItemName(what));
if oldPrice = 0 then
write(Chout; " currently not for sale");
else
write(Chout; " currently offered at $",
oldPrice / 10, '.', oldPrice % 10, '0');
fi;
writeln(Chout; " at ", r, ',', c);
skipBlanks();
if reqPosRange1(&price, cost * 127, "New price? ") then
if price / cost = 0 and price ~= 0 then
writeln(Chout; "Price too low, must be at least $",
cost / 10, '.', cost % 10, '0');
else
price := price / cost;
if price = 0 then
if oldPrice = 0 then
writeln(Chout; "OK, ", getItemName(what),
" not offered");
else
s.s_threshold[what] := 0;
if s.s_threshold[it_shells] = 0 and
s.s_threshold[it_guns] = 0 and
s.s_threshold[it_planes] = 0 and
s.s_threshold[it_ore] = 0 and
s.s_threshold[it_bars] = 0 then
offer.of_state := of_none;
writeOffer(offerNumber, offer);
writeln(Chout; "Lot \#", offerNumber,
" withdrawn");
s.s_threshold[it_civilians] := 0;
s.s_threshold[it_military] := 0;
fi;
writeSector(r, c, s);
fi;
else
writeln(Chout; "Price set to $", price * cost / 10,
'.', price * cost % 10, '0');
if not gotOffer then
offerNumber := World.w_offerNext;
World.w_offerNext := World.w_offerNext + 1;
writeln(Chout; "This item is lot \#",
offerNumber);
else
writeln(Chout; "Lot \#", offerNumber,
" updated");
fi;
offer.of_state := of_sector;
offer.of_who := ThisCountryNumber;
offer.of_.of_sect.of_row := transRow(r);
offer.of_.of_sect.of_col := transCol(c);
writeOffer(offerNumber, offer);
s.s_threshold[it_civilians] :=
World.w_offerNext >> 8;
s.s_threshold[it_military] := World.w_offerNext;
s.s_threshold[what] := price;
writeSector(r, c, s);
fi;
fi;
else
if oldPrice = 0 then
writeln(Chout; "OK, ", getItemName(what),
" not offered");
else
writeln(Chout; "OK, price not changed");
fi;
fi;
true
fi
else
false
fi
else
false
fi
corp;
/*
* printOffer - print out an offer. Return 'false' if it is gone.
*/
proc printOffer(uint offerNumber; Offer_t offer)bool:
Sector_t s;
Ship_t ship;
uint cost;
int r, c;
ItemType_t it;
bool needMess;
needMess := false;
if offer.of_state = of_ship then
readShip(offer.of_.of_shipNumber, ship);
if ship.sh_owner ~= offer.of_who then
offer.of_state := of_none;
writeOffer(offerNumber, offer);
ship.sh_price := 0;
writeShip(offer.of_.of_shipNumber, ship);
needMess := true;
else
writeln(Chout; "Lot \#", offerNumber, ':');
writeln(Chout; getShipName(ship.sh_type), " \#",
offer.of_.of_shipNumber, " at ",
unTransRow(ThisCountryNumber, ship.sh_row), ',',
unTransCol(ThisCountryNumber, ship.sh_col),
": ", ship.sh_efficiency, "%, crew: ",
ship.sh_crew, ", guns: ", ship.sh_guns,
", shells: ", ship.sh_shells, " @ $", ship.sh_price,
" (total $",
ship.sh_price * World.w_shipCost[ship.sh_type], ')');
fi;
elif offer.of_state = of_sector then
r := unTransRow(ThisCountryNumber, offer.of_.of_sect.of_row);
c := unTransCol(ThisCountryNumber, offer.of_.of_sect.of_col);
readSector(r, c, s);
if s.s_owner ~= offer.of_who or s.s_type ~= s_exchange or
s.s_efficiency < 60 then
offer.of_state := of_none;
writeOffer(offerNumber, offer);
for it from it_first upto it_last do
s.s_threshold[it] := 0;
od;
writeSector(r, c, s);
needMess := true;
else
writeln(Chout; "Lot \#", offerNumber, ':');
for it from it_shells upto it_bars do
cost := getItemCost(it) * s.s_threshold[it];
if cost ~= 0 then
write(Chout; readQuan(s, it), ' ', getItemName(it), " @ $",
cost / 10, '.', cost % 10, "0 ");
fi;
od;
writeln(Chout;);
fi;
fi;
if needMess then
if offer.of_who = ThisCountryNumber then
writeln(Chout; "Your lot \#", offerNumber, " cancelled");
else
telegramStart(DEITY, offer.of_who);
writeln(TelegramChannel; "Your lot \#", offerNumber, " cancelled");
telegramEnd();
fi;
fi;
offer.of_state ~= of_none
corp;
proc cmd_report()bool:
Offer_t offer;
uint choice, offerNumber;
bool doNaval, doLand;
if InputPtr* >= '0' and InputPtr* <= '9' and World.w_offerNext ~= 0 then
if getPosRange(&offerNumber, World.w_offerNext - 1) then
readOffer(offerNumber, offer);
pretend(printOffer(offerNumber, offer), void);
true
else
false
fi
else
doNaval := true;
doLand := true;
if InputPtr* ~= '\e' then
doNaval := false;
doLand := false;
if getChoice(&choice, "naval\eland\e") then
if choice = 0 then
doNaval := true;
else
doLand := true;
fi;
fi;
fi;
if doLand or doNaval then
write(Chout; " Empire Trade Report as of ");
writeDate(CurrentTime());
writeln(Chout;);
writeln(Chout;);
if World.w_offerNext ~= 0 then
for offerNumber from 0 upto World.w_offerNext - 1 do
readOffer(offerNumber, offer);
if (offer.of_state = of_ship and doNaval or
offer.of_state = of_sector and doLand) and
printOffer(offerNumber, offer) then
writeln(Chout;);
fi;
od;
fi;
true
else
false
fi
fi
corp;
/*
* doBuy - try to buy a given item from an exchange sector. Return 'true' if
* we should continue, 'false' if insufficient funds.
*/
proc doBuy(Sector_t s1, s2; ItemType_t what; *ulong pFunds)bool:
uint cost, count, max;
[100] char buff;
channel output text promptChannel;
cost := getItemCost(what) * s1.s_threshold[what];
if cost ~= 0 then
/* note assumption that bundle size in exchange is 1 for everything */
max := min(readQuan(s1, what), 127 - readQuan(s2, what));
open(promptChannel, &buff[0]);
write(promptChannel; "Buy how many ", getItemName(what), " at $",
cost / 10, '.', cost % 10, "0 (max ", max, ")? ");
close(promptChannel);
if reqPosRange(&count, max, &buff[0]) then
cost := cost * count / 10;
if pFunds* > cost then
writeQuan(s1, what, readQuan(s1, what) - count);
pFunds* := pFunds* - cost;
writeQuan(s2, what, readQuan(s2, what) + count);
true
else
err("insufficient funds");
false
fi
else
writeln(Chout; "OK, none bought");
true
fi
else
true
fi
corp;
/*
* makeSale - a sale for the given amount has been made.
*/
proc makeSale(uint seller, offerNumber; ulong amount)void:
ThisCountry*.c_money := ThisCountry*.c_money - amount;
Country[seller].c_money := Country[seller].c_money + amount;
telegramStart(DEITY, seller);
writeln(TelegramChannel; "You made a sale (lot \#", offerNumber,
") to ", &ThisCountry*.c_name[0]);
telegramEnd();
news(n_make_sale, seller, ThisCountryNumber);
writeln(Chout; "You are now $", amount, " poorer!");
corp;
proc cmd_buy()bool:
Offer_t offer;
Ship_t ship;
Sector_t s1, s2;
long cost;
ulong funds;
uint which;
int r1, c1, r2, c2;
if reqPosRange(&which, World.w_offerNext - 1, "Buy which lot? ") then
readOffer(which, offer);
if printOffer(which, offer) then
if offer.of_who = ThisCountryNumber then
err("can't sell to yourself");
false
elif offer.of_state = of_ship then
readShip(offer.of_.of_shipNumber, ship);
cost := ship.sh_price * World.w_shipCost[ship.sh_type];
if cost < ThisCountry*.c_money then
if ask("Buy the ship? ") then
ship.sh_price := 0;
ship.sh_owner := ThisCountryNumber;
writeShip(offer.of_.of_shipNumber, ship);
offer.of_state := of_none;
writeOffer(which, offer);
writeln(Chout; "You now own ",
getShipName(ship.sh_type),
" \#", offer.of_.of_shipNumber);
makeSale(offer.of_who, which, cost);
else
writeln("OK, you chickened out");
fi;
else
err("you don't have enough money");
fi;
true
else /* offer.of_state = of_sector */
skipBlanks();
if reqSector(&r2, &c2, "Exchange to deliver to? ") then
readSector(r2, c2, s2);
if s2.s_owner ~= ThisCountryNumber then
err("you don't own that sector");
elif s2.s_type ~= s_exchange then
err("that sector is not an exchange");
elif s2.s_efficiency < 60 then
err("exchange not efficient enough yet");
else
funds := ThisCountry*.c_money;
r1 := unTransRow(ThisCountryNumber,
offer.of_.of_sect.of_row);
c1 := unTransCol(ThisCountryNumber,
offer.of_.of_sect.of_col);
readSector(r1, c1, s1);
if doBuy(s1, s2, it_shells, &funds) and
doBuy(s1, s2, it_guns, &funds) and
doBuy(s1, s2, it_planes, &funds) and
doBuy(s1, s2, it_ore, &funds) and
doBuy(s1, s2, it_bars, &funds) then
if funds ~= ThisCountry*.c_money then
writeSector(r1, c1, s1);
writeSector(r2, c2, s2);
/* the offer sticks around */
makeSale(offer.of_who, which,
ThisCountry*.c_money - funds);
fi;
fi;
fi;
true
else
false
fi
fi
else
writeln(Chout; "Lot \#", which, " is not available");
false
fi
else
false
fi
corp;